<?php

/**
 * 用户相关接口
 */
namespace Api\Controller;

use Think\Controller;

class ApiBaseController extends Controller
{
    protected function _checkToken($token)
    {
        return S($token);
    }

    protected function _successData($returnData, $msg = "查询成功")
    {
        $data = array('Success' => true,
            'ResultCode' => '0000',
            'ReturnData' => $returnData,
            'Message' => $msg
        );
        $this->ajaxReturn($data);
    }

    protected function _errorData($code, $message)
    {
        $ReturnData = array();
        $data = array('Success' => true,
            'ResultCode' => $code . "",
            'ReturnData' => $ReturnData,
            'Message' => $message . ''
        );
        $this->ajaxReturn($data);
    }

    protected function _checkMobile($mobile)
    {
        if (preg_match("/^1[34578]\d{9}$/", $mobile)) {
            return true;
        } else {
            return false;
        }
    }

    protected function _getUserData()
    {
        $token = $_REQUEST["token"];
        $userData = $this->_checkToken($token);
        //$userData =array('mobile'=>'13854054082',"userId"=>20);
        if ($userData == false) {
            $ReturnData = array();
            $data = array('Success' => false,
                'ResultCode' => '0005',
                'ReturnData' => $ReturnData,
                'Message' => '用户未登录'
            );
            $this->ajaxReturn($data);
        } else {
            return $userData;
        }
    }

    public function getDomain()
    {
        return "http://" . $_SERVER['SERVER_NAME'] ;
    }

}

